package cn.glutnn.controller;

import cn.glutnn.entity.Business;
import cn.glutnn.entity.Result;
import cn.glutnn.service.BusinessService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商家表(Business)表控制层
 *
 * @author msh
 * @since 2024-12-10 16:26:03
 */
@RestController
@RequestMapping("/business")
public class BusinessController {
    /**
     * 服务对象
     */
    @Autowired
    private BusinessService businessService;

    @GetMapping("/listBusinessByFoodTypeId")
    public Result<List<Business>> listBusinessByFoodTypeId(Integer foodTypeId) {
        return Result.success(businessService.lambdaQuery().eq(Business::getFoodTypeId, foodTypeId).list());
    }

    @GetMapping("/{businessId}")
    public Result<Business> getBusinessById(@PathVariable("businessId") Integer businessId) {
        return Result.success(businessService.getById(businessId));
    }

    // 查询所有商家
    @GetMapping("/list")
    public Result<List<Business>> list() {
        LambdaQueryWrapper<Business> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Business::getBusinessId);
        return Result.success(businessService.list(wrapper));
    }

    // 搜索商家
    @GetMapping("/search")
    public Result<List<Business>> search(@RequestParam String keyword){
        return Result.success(businessService.lambdaQuery().like(Business::getBusinessName, keyword).list());
    }


    @PostMapping("/updateMonthlySales")
    public Result updateMonthlySales() {
        businessService.updateMonthlySales();
        return Result.success("更新成功");
    }

}

